package com.fanrui.code.match;

import java.util.Map;

import com.fanrui.code.config.ConfigFileManager;
import com.fanrui.code.entity.MahjongTableConfig;
import com.fanrui.proto.cmd.MahjongGameType;
import com.fanrui.proto.cmd.MatchGameLevel;

/**
 * @ClassName: TableConfig
 * @Description: 房间配置
 * @author bear
 */
public class TableConfig {
	// singleton
	private TableConfig() {
	}

	private static class TableConfigSingleton {
		private static TableConfig instance = new TableConfig();
	}

	public static TableConfig getInstance() {
		return TableConfigSingleton.instance;
	}

	/**
	 * 匹配场房间配置
	 */
	private Map<Integer, MahjongTableConfig> mahjongConfigs = null;

	public void init() {
		mahjongConfigs = ConfigFileManager.getInstance().getConfigFilesByName(MahjongTableConfig.class);
	}

	/**  
	*  根据房间类型和等级查找房间
	*  @param level
	*  @param type
	*  @return    
	*  MahjongTableConfig    
	*/  
	public MahjongTableConfig getMahjongTableConfig(MatchGameLevel level, MahjongGameType type) {
		if (mahjongConfigs != null && !mahjongConfigs.isEmpty()) {
			for (MahjongTableConfig config : mahjongConfigs.values()) {
				if (config.getTableLevel() == level.getNumber() && config.getGameType() == type.getNumber()) {
					return config;
				}
			}
		}
		return null;
	}
	
	/**  
	*  获取所有的房间配置
	*  @return    
	*  Map<Integer,MahjongTableConfig>    
	*/  
	public Map<Integer, MahjongTableConfig> getAllMahjongConfigs(){
		//TODO 应该复制一份 防止configs逸出
		return mahjongConfigs;
	}
	
}
